home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 201-225 / disk_203 / gurusguide / swimsg.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  4KB  |  131 lines

  1. /************************************************************************
  2. **********                                                     **********
  3. ********** M E S S A G E   S O F T W A R E   I N T E R R U P T **********
  4. ********** --------------------------------------------------- **********
  5. **********                                                     **********
  6. **********        Copyright (C) 1988 Sassenrath Research       **********
  7. **********                All Rights Reserved.                 **********
  8. **********                                                     **********
  9. **********    Example from the "Guru's Guide, Meditation #1"   **********
  10. **********                                                     **********
  11. *************************************************************************
  12. **                                                                     **
  13. **                            - NOTICE -                               **
  14. **                                                                     **
  15. **  The "Guru's Guide, Meditation #1" contains detailed information    **
  16. **  about Amiga interrupts as well as a complete discussion of this    **
  17. **  and other examples.  Meditation #1 and all of its examples were    **
  18. **  written by Carl Sassenrath, the architect of Amiga's multitasking  **
  19. **  operating system.  Copies of the "Guru's Guide" may be obtained    **
  20. **  from:                                                              **
  21. **           GURU'S GUIDE, P.O. BOX 1510, UKIAH, CA 95482              **
  22. **                                                                     **
  23. **  Please include a check for $14.95, plus $1.50 shipping ($4.00 if   **
  24. **  outside North America).  CA residents add 6% sales tax.            **
  25. **                                                                     **
  26. **  This example may be used for any purposes, commercial, personal,   **
  27. **  public, and private, so long as ALL of the above text, copyright,  **
  28. **  mailing address, and this notice are retained in their entirety.   **
  29. **                                                                     **
  30. **  THIS EXAMPLE IS PROVIDED WITHOUT WARRANTY OF ANY KIND.             **
  31. **                                                                     **
  32. ************************************************************************/
  33.  
  34. /*
  35. **  COMPILATION NOTE:
  36. **
  37. **  Compiled under MANX AZTEC C 3.6A.  Use the +L compiler option
  38. **  and the "c32" library.  Link with intrsup.o
  39. */
  40.  
  41.  
  42. #include <exec/exec.h>
  43.  
  44. struct MsgPort *IPort = NULL;
  45. struct MsgPort *RPort = NULL;
  46. struct Interrupt *Intr = NULL;
  47. long ASignal = -1;
  48.  
  49.  
  50. /* Interrupt Processing Code */
  51. IntrProc()
  52. {
  53.     extern struct Message *GetMsg();
  54.     struct Message *msg;
  55.  
  56.     int_start();
  57.  
  58.     msg = GetMsg(IPort);
  59.     if (msg != NULL) ReplyMsg(msg);
  60.  
  61.     int_end();
  62. }
  63.  
  64.  
  65. main()
  66. {
  67.     struct Message msg;
  68.  
  69.     MainInit();
  70.  
  71.     msg.mn_Node.ln_Type = NT_MESSAGE;
  72.     msg.mn_Node.ln_Name = "swi.message";
  73.     msg.mn_ReplyPort = RPort;
  74.  
  75.     puts("Causing interrupt...");
  76.     PutMsg(IPort, &msg);
  77.  
  78.     puts("Awaiting reply...");
  79.     WaitPort(RPort);
  80.  
  81.     puts("Got reply...");
  82.     GetMsg(RPort);
  83.  
  84.     MainExit();
  85. }
  86.  
  87.  
  88. MainInit()
  89. {
  90.     extern struct Interrupt *MakeIntr();
  91.     extern struct MsgPort *CreatePort();
  92.     extern struct Task *FindTask();
  93.     extern int Enable_Abort;
  94.  
  95.     Enable_Abort = 0;    /* prevent a CTRL-C */
  96.  
  97.     Intr = MakeIntr("softint.example",-16,&IntrProc,0);
  98.     if (Intr == NULL) MainExit(201);
  99.  
  100.     ASignal = AllocSignal(-1);
  101.     if (ASignal == -1) MainExit(202);
  102.  
  103.     IPort = CreatePort("swi.port", 0);
  104.     if (IPort == NULL) MainExit(203);
  105.  
  106.     RPort = CreatePort("swi.reply.port", 0);
  107.     if (RPort == NULL) MainExit(204);
  108.  
  109.     IPort->mp_SoftInt = (struct Task *) Intr;
  110.     IPort->mp_Flags = PA_SOFTINT;
  111.  
  112.     RPort->mp_SigBit = ASignal;
  113.     RPort->mp_SigTask = FindTask(NULL);
  114.     RPort->mp_Flags = PA_SIGNAL;
  115. }
  116.  
  117.  
  118. MainExit(error)
  119.     int error;
  120. {
  121.     FreeIntr(Intr);
  122.  
  123.     if (IPort != NULL) DeletePort(IPort);
  124.  
  125.     if (RPort != NULL) DeletePort(RPort);
  126.  
  127.     if (ASignal != -1) FreeSignal(ASignal);
  128.  
  129.     exit(error);
  130. }
  131.